<?php
/**
* @package Frontend-User-Access (com_frontenduseraccess)
* @version 3.0.8
* @copyright Copyright (C) 2008 Carsten Engel. All rights reserved.
* @license GPL versions free/trial/pro
* @author http://www.pages-and-items.com
* @joomla Joomla is Free Software
*/

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.view');

class frontenduseraccessViewMenuaccess extends JView
{
	function display($tpl = null)
	{
		$database = JFactory::getDBO();
		$controller = new frontenduseraccessController();	
		$this->assignRef('controller', $controller);	
		
		//toolbar			
		JToolBarHelper::custom( 'menuaccess_save', 'save.png', 'save_f2.png', JText::_('save'), false, false );	
		
		//do limits just to parse view to session var
		$limitstart	= $controller->pagination_get_limitstart();		
		
		//get usergroups from db
		$fua_usergroups = $controller->get_usergroups();		
		$this->assignRef('fua_usergroups', $fua_usergroups);
		
		//get menu access from db
		$controller->db->setQuery("SELECT menuid_groupid FROM #__fua_menuaccess");
		$access_menuitems = $controller->db->loadResultArray();
		$this->assignRef('access_menuitems', $access_menuitems);
		
		//get menu types from db
		$controller->db->setQuery("SELECT title, menutype FROM #__menu_types ORDER BY title ASC"  );
		$menutypes = $controller->db->loadObjectList();
		$menutypes_db = array();	
		foreach($menutypes as $menutype_db){
			$fixed_type = str_replace('-','separator',$menutype_db->menutype);	
			$fixed_type = str_replace(' ','spacer',$fixed_type);			
			$new_menutype = array($fixed_type,$menutype_db->title);
			array_push($menutypes_db, $new_menutype);					
		}	
		$this->assignRef('menu_types', $menutypes_db);
		
		//get menuitems from db
		$controller->db->setQuery("SELECT id, menutype, name, parent, access, ordering FROM #__menu WHERE (published='0' OR published='1') ORDER BY ordering ASC");
		$fua_menu_items = $controller->db->loadObjectList();		
		$this->assignRef('fua_menu_items', $fua_menu_items);
		
		$model =& $this->getModel('menuaccess');
		$this->assignRef('model', $model);
		
		parent::display($tpl);
	}
	
}
?>